package cn.wyd.shield.token.jwt;

import java.util.UUID;

public class JwtToken {
    private String iss;//签发者
    private String sub;//提交者
    private String aud;//接受者用户
    private Long exp;//过期时间
    private Long nbf;//启用时间
    private Long iat;//签发时间
    private String jti;//唯一标识

    private String uid;
    private String userName;


    private String token;

    public String getIss() {
        return iss;
    }

    public void setIss(String iss) {
        this.iss = iss;
    }

    public String getSub() {
        return sub;
    }

    public void setSub(String sub) {
        this.sub = sub;
    }

    public String getAud() {
        return aud;
    }

    public void setAud(String aud) {
        this.aud = aud;
    }

    public Long getExp() {
        return exp;
    }

    public void setExp(Long exp) {
        this.exp = exp;
    }

    public Long getNbf() {
        return nbf;
    }

    public void setNbf(Long nbf) {
        this.nbf = nbf;
    }

    public Long getIat() {
        return iat;
    }

    public void setIat(Long iat) {
        this.iat = iat;
    }

    public String getJti() {
        return jti;
    }

    public void setJti(String jti) {
        this.jti = jti;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("{");
        sb.append("iss:'").append(iss).append('\'');
        sb.append(", sub:'").append(sub).append('\'');
        sb.append(", aud:'").append(aud).append('\'');
        sb.append(", exp:").append(exp);
        sb.append(", nbf:").append(nbf);
        sb.append(", iat:").append(iat);
        sb.append(", jti:'").append(jti).append('\'');
        sb.append(", uid:'").append(uid).append('\'');
        sb.append(", userName:'").append(userName).append('\'');
        sb.append('}');
        return sb.toString();
    }




    public String toPlayLoadString() {
        final StringBuffer sb = new StringBuffer("{");
        sb.append("iss:'").append(iss).append('\'');
//        sb.append(", sub:'").append(sub).append('\'');
//        sb.append(", aud:'").append(aud).append('\'');
        sb.append(", exp:").append(exp);
//        sb.append(", nbf:").append(nbf);
//        sb.append(", iat:").append(iat);
        sb.append(", jti:'").append(jti).append('\'');
        sb.append(", uid:'").append(uid).append('\'');
        sb.append(", userName:'").append(userName).append('\'');
        sb.append('}');
        return sb.toString();
    }




    public JwtToken(String uid, String userName) {
        this.uid = uid;
        this.userName = userName;
        this.iss = "wyd-server";
        Long cur = System.currentTimeMillis()/1000;
        this.exp = cur+60*60*24;
        this.nbf = cur;
        this.iat = cur;
        this.jti = UUID.randomUUID().toString()+cur;
    }

    public JwtToken(String iss, Long exp, String jti, String uid, String userName) {
        this.iss = iss;
        this.exp = exp;
        this.jti = jti;
        this.uid = uid;
        this.userName = userName;
    }
}
